﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Data.OleDb;
namespace MarketFunds
{
    
    public class IndustryDiffItem
    {
        /// <summary>
        /// 
        /// </summary>
        public string f12 { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int f13 { get; set; }

        /// <summary>
        /// 化学制药
        /// </summary>
        public string f14 { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public double f62 { get; set; }

    }



    public class IndustryData
    {
        /// <summary>
        /// 
        /// </summary>
        public double total { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public List<IndustryDiffItem> diff { get; set; }

    }



    public class IndustryRoot
    {
        /// <summary>
        /// 
        /// </summary>
        public int rc { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int rt { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public double svr { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int lt { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int full { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string dlmkts { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public IndustryData data { get; set; }

    }

    public class IndustryDataJSON
    {
        public OleDbConnection dbconn = null;
        public IndustryRoot DataRoot = null;
        public string m_strDate = string.Empty;

        
        public string GetPureIndustryDataJSON(string strJSON)
        {
            if (strJSON.Trim().Length == 0)
                return strJSON.Trim();
            //找到第一个( ;
            int nFirstPos = strJSON.IndexOf("(");

            int nLastPos = strJSON.LastIndexOf(")");
            string strTemp = strJSON.Substring(nFirstPos + 1, nLastPos - nFirstPos - 1);
            return strTemp;
        }
        public bool GetIndustryDataByJSON(string strJSON)
        {
            
            IndustryRoot oro = JsonConvert.DeserializeObject<IndustryRoot>(strJSON);
            
            this.DataRoot = oro;


            for (int i = 0; i < this.DataRoot.data.diff.Count(); i++)
            {
                IndustryDiffItem diff = this.DataRoot.data.diff[i];
                Console.WriteLine(diff.f12 + "," + diff.f14 + "," + diff.f62);
                    
                //然后写入数据库
                string strSql = string.Format("insert into industryZB (hddate,zb,hyname,TotalHYFunds) values (#{0}#,'{1}','{2}',{3})",
                    m_strDate, diff.f12, diff.f14, diff.f62);
                OleDbCommand cmd = new OleDbCommand(strSql, dbconn);
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }
        
            return true;
        }
    }
    class IndustryData1
    {
        public string scode = string.Empty;
        public string sname = string.Empty;
        public double dFunds = 0;
        public double dPrevFunds = 0;
        public double dFundsDiff = 0;
        public int nInOrOut = 0;  //净流入流出的天数
    }
}
